//
// Created by francklinson on 2021/5/25.
//
/*幂集。编写一种方法，返回某集合的所有子集。集合中不包含重复的元素。

说明：解集不能包含重复的子集。*/
#include <vector>
#include <iostream>

using namespace std;

class Solution {
    vector<int> v;
public:
    vector<vector<int>> subsets(vector<int> &nums) {
        this->v = nums;
        vector<vector<int>> ans;
        vector<int> cur;
        dfs(ans, cur, 0, (int) nums.size());
        return ans;
    }

    void dfs(vector<vector<int>> &ans, vector<int> &cur, int index, int n) {
        ans.push_back(cur);
//        if (index == n) return;
        for (int i = index; i < n; ++i) {
            cur.push_back(v[i]);
            dfs(ans, cur, i + 1, n);
            cur.pop_back();
        }
    }
};

int main() {
    vector<int> v{1, 2, 3};
    Solution sol;
    auto ans = sol.subsets(v);
    for (auto &x:ans) {
        for (auto &y:x) {
            cout << to_string(y) << " ";
        }
        cout << endl;
    }
    return 0;
}